import $api from '@/api'
import { assign } from 'lodash';

import { ElMessage } from 'element-plus'
import { createStore } from 'vuex'
import createPersistedState from "vuex-persistedstate"
export default createStore({
  plugins: [createPersistedState({
    storage: window.sessionStorage
  })],
  state: {
    shuiguocha: [],
    buycar: [],
  },

  getters: {
    getSshuiguocha(state){
      return state.shuiguocha
    }
  },

  actions: {
    async getData({ commit, state }) {
      const res = await $api.get("/shuiguocha?$limit=50",
      )
      commit("setData", res)
    },
    async getbuycar({ commit, state }, item) {
      console.log("state buycar",state);
      commit("buycar",state)
    }

  },
  mutations: {
    setData(state, payload) {
      const { status, data } = payload
      if (status === 200) {
        return assign(state.shuiguocha, data.data)
        // return state.shuiguocha.push(...data.data)
      }
      return ElMessage.error("数据跑丢了············");
    },
    
    buycar(state, payload) {
      
     console.log("buycar",state,payload);
    },
  },
  modules: {
  }
})
